import dateFormat from "vux/src/tools/date/format.js";

import dataTimeFilter from "../../common/dataTimeFilter/dataTimeFilter";
import { addClass, removeClass } from "@/assets/js/dom.js";
import template from "./conversionRecordTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  components: {
    dataTimeFilter,
  },
  data() {
    return {
      recordList: [],
      lotteryType: this.$route.query.id,

      type: "",
      datePicker: false,
      beginTime: dateFormat(new Date(), "YYYY-MM-DD"),
      endTime: dateFormat(new Date(), "YYYY-MM-DD"),
      page: 1,
    };
  },
  created() {
    this.resetAll();
  },
  mounted() {},
  methods: {
    pullingDown() {
      this.page = 1;
      this._getOrdersList("down");
    },
    pullingUp() {
      if (this.flag) {
        this.$refs.scroll.forceUpdate(false);
        return;
      }
      this.page += 1;
      this._getOrdersList("up");
    },
    resetAll() {
      let vm = this;
      vm.value1 = dateFormat(new Date(), "YYYY-MM-DD");
      vm.value2 = dateFormat(new Date(), "YYYY-MM-DD");
      vm.beginTime = dateFormat(new Date(), "YYYY-MM-DD");
      vm.endTime = dateFormat(new Date(), "YYYY-MM-DD");
      vm.page = 1;
      vm._getOrdersList();
    },
    _getOrdersList(type) {
      let vm = this;
      let params = {};
      params.token = localStorage.getItem("token");
      params.start_time = vm.beginTime;
      params.end_time = vm.endTime;
      params.game_plat_id = vm.lotteryType;
      params.page = vm.page;
      if (!type) {
        vm.$vux.loading.show();
      }
      vm.$http
        .post(vm.urlRequest + "?m=api&c=game&a=getOrdersList", params)
        .then((res) => {
          if (res.status == 0) {
            if (vm.page == 1) {
              vm.recordList = res.data;
            } else {
              vm.recordList = vm.recordList.concat(res.data);
            }
            if (res.data.length < 10) {
              vm.flag = true;
            } else {
              vm.flag = false;
            }
          }
          vm.$vux.loading.hide();
        })
        .catch((err) => {
          vm.$vux.loading.hide();
          console.log(err);
        });
    },
    pickHide(data) {
      this.datePicker = data;
    },
    getTime(data) {
      let begin = new Date(data[0]);
      let end = new Date(data[1]);
      this.endTime = data[1];
      this.beginTime = data[0];
      this.datePicker = false;
      this.page = 1;
      this._getOrdersList();
    },
  },
  activated() {},
  deactivated() {},
  watch: {},
};

// WEBPACK FOOTER //
// ./src/components/personalCenter/bettingRecord/conversionRecord.vue
